import http from "@/api";
import { ResultData } from "@/api/interface/index";

export namespace Department {
  export interface DepartmentTree {
    id: string;
    name: string;
    children?: DepartmentTree[];
  }
  export interface DepartmentInsertVo {
    departmentName: string;
    pid: string;
    remark: string;
    orderNum: number;
  }
  export interface DepartmentUpdateVo {
    id: string;
    departmentName: string;
    pid: string;
    remark: string;
    orderNum: number;
  }
  export interface DepartmentOut {
    id: string;
    departmentName: string;
    pid: string;
    parentName: string;
    createUser: string;
    createTime: string;
    updateUser: string;
    updateTime: string;
    remark: string;
    orderNum: number;
  }
}
export const getDepartmentTree = () => {
  return http.get<ResultData<Department.DepartmentTree[]>>("/admin/department/getDepartmentTree");
};

export const addDepartment = (params: Department.DepartmentInsertVo) => {
  return http.post("/admin/department/insert", params);
};

export const updateDepartment = (params: Department.DepartmentUpdateVo) => {
  return http.post("/admin/department/update", params);
};

export const deleteDepartment = (id: string) => {
  return http.delete("/admin/department/delete", { id: id });
};

export const getDepartmentById = (id: string) => {
  return http.get<Department.DepartmentOut>("/admin/department/selectById", { id: id });
};
